package com.gf.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gf.base.type.Role;
import com.gf.common.bean.Page;
import com.gf.user.dao.SuperDao;
import com.gf.user.model.User;
import com.gf.user.service.SuperService;

@Transactional
@Service("superService")
public class SuperServiceImpl implements SuperService {

	@Autowired
	private SuperDao superDao;

	@Override
	public Page getAdmins(int currentPage, int pageSize) {

		Page page = new Page();
		page.setCurpage(currentPage);
		page.setPageSize(pageSize);
		int total = superDao.queryAdminsCount();
		page.setTotal(total);
		List<User> users = superDao.queryAdmins(page);
		page.setResults(users);
		return page;
	}

	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	@Override
	public boolean authorizeAdmin(long adminId) {

		return superDao.updateUserToAdminOrNot(adminId, Role.ADMIN);
	}

	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	@Override
	public boolean fireAdmin(long adminId) {

		return superDao.updateUserToAdminOrNot(adminId, Role.NORMAL);
	}

	@Override
	public long updateAbout(String content) {
		return superDao.insertAbout(content);
	}

}
